﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
using DTO;
//0712455
namespace DAO
{
    public class NganHangDAO
    {
        public static List<NganHangDTO> LayDanhSach()
        {
            SqlConnection cnn = KetNoiCSDL.TaoKetNoi();
            string query = "select * from Ngan_Hang";
            SqlCommand cmd = new SqlCommand(query, cnn);

            cnn.Open();
            List<NganHangDTO> lstNganHang = new List<NganHangDTO>();
            try
            {
                SqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    NganHangDTO nganHangDto = new NganHangDTO();
                    nganHangDto.MaNganHang = (int)dr["MaNganHang"];
                    nganHangDto.TenNganHang = dr["TenNganHang"].ToString();

                    lstNganHang.Add(nganHangDto);
                }
                cnn.Close();
                return lstNganHang;

            }
            catch (Exception ex)
            {
                if (cnn.State == ConnectionState.Open)
                    cnn.Close();
                throw ex;
            }
            
        }
    }
}
